<?php
namespace data\site;
use \data\BaseData;
/**
 * 登录日志
 */
class LoginLogsData extends BaseData{
    
    
    /**
     * 添加登录日志
     */
    public function add($data){        
        $check = [
            'userid'    => ['check'=>'must','msg'=> '登录用户ID','reg'=>'int'],
            'status'    => ['reg'=> [1,2]],
            'ip'        => '',
            'area'      => '',
            'useragent' => '',
            'addtime'   => ['val'=> SYS_TIME],
        ];
        $save = $this->verifyData($check,$data);
        return M('site_admin_logs_login')->insertGetId($save);
    }    
    
    /**
     * 读取用户登录次数
     */
    public function getLastLoginList($param){
        $where['userid'] = array("in",$param['userid']);
        $field = "count(userid) as logins,userid";
        $list = M("site_admin_logs_login")->field($field)->where($where)->group("userid")->select();
        return $list;
    }
    
    /**
     * 读取用户登录次数
     */
    public function getLastLogin($userid){
        $where['userid'] = $userid;
        $list = M("site_admin_logs_login")->where($where)->order('id desc')->find();
        return $list;
    }
}